<!DOCTYPE html>
<html lang="">
<head>
    <meta charset="utf-8">
    <title>{$page_info.title}</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
</head>

<body>
<div style="padding: 8px!important;">
    <div class="layui-card">
        <div class="layui-card-body">
            <table class="layui-hide" id="{$table_id}_data_list" lay-filter="{$table_id}_data_list"></table>
        </div>
    </div>
</div>
<script type="text/html" id="{$table_id}_rightbar">
    <a class="layui-btn layui-btn-xs {{= (d.no_edit === 1) ? 'layui-hide' : '' }} {if(isset($operate.r_bar_edit)&&($operate.r_bar_edit === 1))}layui-hide{/if}" lay-event="{$table_id}_edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs {{= (d.no_delete === 1) ? 'layui-hide' : '' }} {if(isset($operate.r_bar_delete)&&($operate.r_bar_delete === 1))}layui-hide{/if}" lay-event="{$table_id}_del">删除</a>
</script>
<script type="text/html" id="{$table_id}_toptool">
    <a class="layui-btn layui-btn-danger layuiadmin-btn-useradmin {if(isset($operate.bar_delete)&&($operate.bar_delete === 1))}layui-hide{/if}" lay-event="{$table_id}_delall">批量删除</a>
    <a class="layui-btn layuiadmin-btn-useradmin {if(isset($operate.bar_add)&&($operate.bar_add === 1))}layui-hide{/if}" lay-event="{$table_id}_add">添加</a>
</script>
<script type="text/html" id="{$table_id}_data_list-table-status">
    <span class="layui-font-{{= (d.status === 1) ? 'green' : (d.status === 2) ? 'red' : 'orange'}}">{{= (d.status === 1) ? '正常' : (d.status === 2) ? '禁止' : '待审核'}}</span>
</script>
<script>
    layui.use(['table', 'treeTable','toast','popup'], function () {
        var $ = layui.jquery;
        var popup = layui.popup;
        var toast = layui.toast;

        var toast = layui.toast;
        {if(isset($table)&&$table === 'tree_table')}
        var table_type = layui.treeTable;
        {else/}
        var table_type = layui.table;
        {/if}

        // 创建渲染实例
        var insTb = table_type.render({
            elem: '#{$table_id}_data_list',
            toolbar: '#{$table_id}_toptool',
            height: 'full-150', // 最大高度减去其他容器已占有的高度差
            css: [ // 重设当前表格样式
                '.layui-table-tool-temp{padding-right: 145px;}'
            ].join(''),
            {if(isset($table)&&$table === 'tree_table')}
            tree: {
                customName: {
                    pid:'pid',
                }
            },
            {/if}
            cellMinWidth: 80,
            totalRow: false, // 开启合计行
            page: true,
            cols: [[
                { type: 'checkbox', fixed: 'left' },
                {foreach $filed as $v}
                {if($v.field === 'status')}
                { field: '{$v.field}', title: '{$v.title}' ,templet: '#{$table_id}_data_list-table-status'},
                {elseif($v.field === 'id')/}
                { field: '{$v.field}', fixed: 'left', width: 80, title: '{$v.title}', sort: true },
                {else/}
                { field: '{$v.field}', title: '{$v.title}' ,templet: function(d){
                    var html = d.{$v.field};
                    {if(isset($v.template))}
                        {if($v.template == 'img')}
                            html = '<img src="'+ d.{$v.field} +'" style="max-height: 30px;max-width: 150px;">';
                        {/if}
                    {/if}
                    return html;
                }},
                {/if}
                {/foreach}
                {title: '操作', width: 134, minWidth: 125, toolbar: '#{$table_id}_rightbar' }
            ]],
            data:{$info|raw},
        });

        table_type.on('tool({$table_id}_data_list)', function (obj) {
            var event = obj.event;
            var data = obj.data;
            if (event === '{$table_id}_del') {
                layer.msg('确认删除吗?',{
                    time:5000,
                    shade:0.3,
                    btn:['删除','取消'],
                    yes:function() {
                        $.post("{:url($operate.delete)}",{id:data.id},function(data){
                            if(data.code === 200){
                                popup.success(data.msg, function () {
                                    PearAdmin.refresh();
                                });
                            }else{
                                toast.error({
                                    message: data.msg,
                                });
                            }
                        })
                    }
                });
            } else if (event === '{$table_id}_edit') {
                layer.open({
                    type:2,
                    title:"编辑",
                    shade:0.3,
                    area:['95%','95%'],
                    content:"{:url($operate.edit)}"+"?id="+data.id,
                    end: function(){
                        PearAdmin.refresh();
                    }
                });
            }
        });

        table_type.on('toolbar({$table_id}_data_list)', function (obj){
            var event = obj.event;
            var id = obj.config.id;
            var checkid = table_type.checkStatus(id);
            if(event === '{$table_id}_delall'){
                if(checkid.data.length == 0){
                    toast.error({
                        message: '请选择需要操作的数据',
                    });
                }else{
                    layer.msg('确认删除选中数据吗?',{
                        time:5000,
                        shade:0.3,
                        btn:['删除','取消'],
                        yes:function() {
                            var ids = new Array(checkid.data.length);
                            for (var i = 0; i < ids.length; i++) {
                                ids[i] = checkid.data[i].id;
                            }
                            $.post("{:url($operate.delete)}",{id:ids},function(data){
                                if(data.code === 200){
                                    popup.success(data.msg, function () {
                                        PearAdmin.refresh();
                                    });
                                }else{
                                    toast.error({
                                        message: data.msg,
                                    });
                                }
                            })
                        }
                    });
                }
            }else if(event === '{$table_id}_add'){
                layer.open({
                    type:2,
                    title:"编辑",
                    shade:0.3,
                    area:['95%','95%'],
                    content:"{:url($operate.save)}",
                    end: function(){
                        PearAdmin.refresh();
                    }
                });
            }
        });
    });
</script>
</body>
</html>